import {
  addDriveParaLibEngineer,
  delDriveParaLibEngineer,
  delDriveParasLibEngineer,
  driveParaLibExcelEngineerExport,
  getDriveParaLibEngineerByPage,
  updateDriveParaLibEngineer,
  uploadDriveParaLibEngineerExcel,
  addDriveParaLibsEngineer,
} from '@/services/drivepara/driveparalibEngineer';
import G120DriveParaColumns from '@/components/Columns/G120Columns'
import { DeleteOutlined, PlusOutlined } from '@ant-design/icons';
import { ModalForm, PageHeaderWrapper, ProCard, ProCardTabsProps, ProColumns, ProFormDependency, ProFormGroup, ProFormInstance, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
import ProList from '@ant-design/pro-list';
import { Button, Modal, Radio, RadioChangeEvent, Space, Tag, message } from 'antd';
import { ReactText, useEffect, useRef, useState } from 'react';
import DriveParaLibCommon from './driveParaLibCommon';
import UploadFile from '@/components/UploadExcel';
import UploadFileSave from '@/components/UploadExcelSave';
import Tree, { DataNode } from 'antd/lib/tree';
import DriveParaLibSubtitle from '@/components/DriveParaCalc/DriveParaLibSubtitle';
import DriveParaLibDescription from '@/components/DriveParaCalc/DriveParaLibDescription';
import DriveParaDescription from '@/components/DriveParaCalc/DriveParaDescription';
import DriveParaSubtitle from '@/components/DriveParaCalc/DriveParaSubtitle';
import G120LibEngCommon from '@/components/DriveParaCalc/G120LibEngCommon';
import { addDriveParaLibG120Eng, addG120DeviceInfo, delDriveParaLibG120Eng, delDriveParasLibG120Eng, delG120DeviceInfo, getDriveParaLibG120EngByPage, updateDriveParaLibG120Eng, updateG120DeviceInfo, uploadDriveParasLibG120EngExcel } from '@/services/drivepara/driveParaLibG120Eng';
import { addDeviceInfoExtra, getDeviceInfoLibByPage } from '@/services/drivepara/deviceInfoLibEng';
import G120LibEngShaftCommon from '@/components/DriveParaCalc/G120LibEngShaftCommon';
import G120DriveParaSubtitle from '@/components/DriveParaCalc/G120DriveParaSubtitle';
import { calcDeviceList } from '@/services/device/deviceInfo';
import DebounceSelect from '@/components/DebounceSelect';
import { history } from 'umi';
import { text } from 'express';
// import type { UploadFile, UploadProps } from 'antd/es/upload/interface';

const DriveParaLib: React.FC<{}> = () => {
  const [expandedRowKeys, setExpandedRowKeys] = useState<readonly ReactText[]>([]);
  const [dataSource, setDataSource] = useState<any[]>([]);
  const [g120DataSource, setG120DataSource] = useState<any[]>([]);
  const [libCommVis, setLibCommVis] = useState(false);
  const [g120CommVis, setG120CommVis] = useState(false);
  const [values, setValues] = useState({});
  const [g120Values, setG120Values] = useState({});
  const [axiosCreate, setAxiosCreate] = useState<Boolean>(false);
  const [g120Create, setG120Create] = useState<Boolean>(false);
  const driveRef = useRef(null);
  const uploadRef = useRef(null);
  const tableRef = useRef(null);
  const formRef = useRef<ProFormInstance>();
  const [uploadVis, setUploadVis] = useState(false);
  const [uploadVisG120, setUploadVisG120] = useState(false);
  const [deviceVisG120, setDeviceVisG120] = useState(false);
  const [deviceG120Values, setDeviceG120Values] = useState({});
  const [grid, setGrid] = useState(true);
  
  const [selectedRowKeys, setSelectedRowKeys] = useState<ReactText[]>([]);
  const formData = new FormData();
  // const [fileList, setFileList] = useState<UploadFile[]>([]);
  const rowSelection = {
    selectedRowKeys,
    onChange: (keys: ReactText[]) => setSelectedRowKeys(keys),
  };
  const actionRef = useRef<ActionType>();
  const tableActionRef = useRef<ActionType>();

  const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]);
  const [checkedKeys, setCheckedKeys] = useState<React.Key[]>(['lib4-0', 'lib4-1', 'lib4-2', 'lib4-3', 'lib4-4',
  'libG120-0', 'libG120-1', 'libG120-2', 'libG120-4-2', 'libG120-5-0-0', 'libG120-5-1-1']);
  const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
  const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true);

  const [kpDefaultChecked, setKpDefaultChecked] = useState(false);

  const [radioValue, setRadioValue] = useState(1);
  const [tab, setTab] = useState('tab1-1');
  const [tabPosition, setTabPosition] = useState<ProCardTabsProps['tabPosition']>('top');
  const [deviceId, setDeviceId] = useState(null);
  const [tab2Disable, setTab2Disable] = useState(true);

  const onRadioChange = (e: RadioChangeEvent) => {
    console.log('radio checked', e.target.value);
    setRadioValue(e.target.value);
    actionRef.current?.reload();
  };


  const columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 40,
      align: 'center',
    },
    {
      title: '轴名称',
      search: false,
      dataIndex: 'shaftName',
      width: 60,
      align: 'center',
    },
    {
      title: '驱动类型',
      width: 60,
      search: false,
      align: 'center',
      key: 'driveType',
      dataIndex: 'driveType',
      valueType: 'select',
      valueEnum: {
        1: { text: 'V90', status: 'Default' },
        2: {
          text: 'S210',
          status: 'success',
        },
      },
    },
    {
      title: '电机订货号',
      search: false,
      align: 'center',
      dataIndex: 'motorOrderNum',
      width: 100,
    },
    // {
    //   title: '电机ID',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'motorId',
    //   width: 60,
    // },
    // {
    //   title: '编码器',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ecoderType',
    //   valueType: 'select',
    //   valueEnum: {
    //     0: { text: '单圈绝对值编码器' },
    //     1: { text: '多圈绝对值编码器' },
    //     2: { text: '增量编码器' },
    //   },
    //   width: 60,
    // },
    // {
    //   title: '抱闸',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'brake',
    //   valueType: 'select',
    //   valueEnum: {
    //     0: { text: '不带抱闸' },
    //     1: { text: '带抱闸' },
    //   },
    //   width: 60,
    // },
    // {
    //   title: '额定电压',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedVoltage',
    //   width: 60,
    // },
    // {
    //   title: '额定电流',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedCurrent',
    //   width: 60,
    // },
    // {
    //   title: '额定功率',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedPower',
    //   width: 60,
    // },
    // {
    //   title: '额定速度',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedSpeed',
    //   width: 60,
    // },
    // {
    //   title: '额定转矩',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'ratedTorque',
    //   width: 60,
    // },
    // {
    //   title: '电机惯量',
    //   search: false,
    //   align: 'center',
    //   dataIndex: 'motorInertia',
    //   width: 60,
    // },
    {
      title: '负载类型',
      align: 'center',
      dataIndex: 'loadType',
      valueType: 'select',
      valueEnum: {
        1: { text: '水平' },
        2: { text: '旋转' },
        3: { text: '垂直' },
        4: { text: '斜坡' },
        5: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '机械结构',
      search: false,
      align: 'center',
      dataIndex: 'mechanicalStructure',
      valueType: 'select',
      valueEnum: {
        1: { text: '丝杠' },
        2: { text: '齿轮齿条' },
        3: { text: '皮带轮' },
        4: { text: '圆盘' },
        5: { text: '辊式带' },
        6: { text: '链条' },
        7: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '通讯报文',
      search: false,
      align: 'center',
      dataIndex: 'commTelegram',
      valueType: 'select',
      valueEnum: {
        105: { text: '105' },
        111: { text: '111' },
        102: { text: '102' },
        3: { text: '3' },
        1: { text: '1' },
      },
      width: 60,
    },
    {
      title: '附加报文',
      search: false,
      align: 'center',
      dataIndex: 'additionalTelegram',
      valueType: 'select',
      valueEnum: {
        999: { text: 'None' },
        750: { text: '750' },
      },
      width: 60,
    },
    {
      title: '控制模式',
      search: false,
      align: 'center',
      dataIndex: 'controlMode',
      valueType: 'select',
      valueEnum: (row) => {
        return {
          1: { text: 'TO' },
          2: { text: 'Epos' },
          3: { text: 'Speed' },
        };
      },
      width: 60,
    },
    {
      title: '电机最大转速',
      search: false,
      align: 'center',
      dataIndex: 'velocityMax',
      width: 70,
    },
    {
      title: '负载转速 (EPOS) (rpm)',
      search: false,
      align: 'center',
      dataIndex: 'gearRationLoad',
      width: 60,
    },
    {
      title: '电机转速 (EPOS) (rpm)',
      search: false,
      align: 'center',
      dataIndex: 'gearRationMotor',
      width: 60,
    },
    {
      title: '10mm对应的LU (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'positionAccuracy',
      width: 100,
    },
    {
      title: '每转LU (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'luLoopEpos',
      width: 60,
    },
    {
      title: '位置环增益 (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'kprEpos',
      width: 80,
    },
    {
      title: '位置环滤波 (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'posFilterEpos',
      width: 80,
    },
    {
      title: '速度前馈系数 (EPOS)',
      search: false,
      align: 'center',
      dataIndex: 'coeffVelEpos',
      width: 60,
    },
    {
      title: 'EPOS 最大速度',
      search: false,
      align: 'center',
      dataIndex: 'vmaxEpos',
      width: 60,
    },
    {
      title: 'EPOS 最大加速度',
      search: false,
      align: 'center',
      dataIndex: 'accmaxEpos',
      width: 80,
    },
    {
      title: 'EPOS 最大减速度',
      search: false,
      align: 'center',
      dataIndex: 'dccmaxEpos',
      width: 60,
    },
    {
      title: 'EPOS 急动限制',
      search: false,
      align: 'center',
      dataIndex: 'jerkEpos',
      width: 60,
    },
    {
      title: 'EPOS 急动限制激活',
      search: false,
      align: 'center',
      dataIndex: 'jerkActiveEpos',
      width: 60,
    },
    {
      title: '速度环增益Kp (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'kpSpeed',
      width: 70,
    },
    {
      title: '速度环积分时间Tn (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'tnSpeed',
      width: 70,
    },
    {
      title: '斜坡上升时间 (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'tincSpeed',
      width: 70,
    },
    {
      title: '斜坡下降时间 (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'tdecSpeed',
      width: 70,
    },
    {
      title: '斜坡圆弧起始时间 (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'tstartSpeed',
      width: 70,
    },
    {
      title: '斜坡圆弧结束时间 (Speed)',
      search: false,
      align: 'center',
      dataIndex: 'tstopSpeed',
      width: 70,
    },
  ];

  const g120Columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 40,
      align: 'center',
    },
    {
      title: '轴名称',
      search: false,
      dataIndex: 'shaftName',
      width: 60,
      align: 'center',
    },
    {
      title: '负载类型',
      align: 'center',
      dataIndex: 'loadType',
      valueType: 'select',
      valueEnum: {
        1: { text: '水平' },
        2: { text: '旋转' },
        3: { text: '垂直' },
        4: { text: '斜坡' },
        5: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '机械结构',
      search: false,
      align: 'center',
      dataIndex: 'mechanicalStructure',
      valueType: 'select',
      valueEnum: {
        1: { text: '丝杠' },
        2: { text: '齿轮齿条' },
        3: { text: '皮带轮' },
        4: { text: '圆盘' },
        5: { text: '辊式带' },
        6: { text: '链条' },
        7: { text: '其它' },
      },
      width: 60,
    },
    {
      title: '控制报文 P922',
      search: false,
      align: 'center',
      dataIndex: 'commTelegram',
      valueType: 'select',
      valueEnum: {
        105: { text: '105' },
        111: { text: '111' },
        102: { text: '102' },
        3: { text: '3' },
        1: { text: '1' },
      },
      width: 60,
    },
    {
      title: '附加报文 P8864',
      search: false,
      align: 'center',
      dataIndex: 'additionalTelegram',
      valueType: 'select',
      valueEnum: {
        999: { text: 'None' },
        750: { text: '750' },
      },
      width: 60,
    },
    {
      title: '控制模式 P1300',
      search: false,
      align: 'center',
      dataIndex: 'controlMode',
      valueType: 'select',
      valueEnum: {
        0: { text: 'V/F' },
        20: { text: '无编码器矢量' },
        21: { text: '编码器速度模式' },
        99: { text: '基本定位模式' },
      },
      width: 60,
    },
    {
      title: '转矩上限值 P1520 [Nm]',
      search: false,
      align: 'center',
      dataIndex: 'torqueLimUpper',
      width: 60,
    },
    {
      title: '转矩下限值 P1521 [Nm]',
      search: false,
      align: 'center',
      dataIndex: 'torqueLimLower',
      width: 60,
    },
    {
      title: '抱闸配置 P1215',
      search: false,
      align: 'center',
      dataIndex: 'brake',
      valueType: 'select',
      valueEnum: {
        0: { text: '无电机抱闸' },
        1: { text: '电机抱闸同顺序控制' },
        2: { text: '电机抱闸始终打开' },
        3: { text: '电机抱闸同顺序控制，通过BICO连接' },
      },
      width: 60,
    },
    {
      title: '抱闸打开时间 P1216 [ms]',
      search: false,
      align: 'center',
      dataIndex: 'tBrakeOpen',
      width: 60,
    },
    {
      title: '抱闸闭合时间 P1217 [ms]',
      search: false,
      align: 'center',
      dataIndex: 'tBrakeClose',
      width: 60,
    },
    {
      title: '制动控制诊断分析 P1278',
      search: false,
      align: 'center',
      dataIndex: 'brakeCtrlDiag',
      valueEnum: {
        0: { text: '带诊断分析的制动控制' },
        1: { text: '不带诊断分析的制动控制' },
      },
      width: 60,
    },
    {
      title: '启动频率 P1351 [%]',
      search: false,
      align: 'center',
      dataIndex: 'brakeStartFrequency',
      width: 60,
    },
    {
      title: '抱闸控制输出DO',
      search: false,
      align: 'center',
      dataIndex: 'brakeCtrlDo',
      width: 60,
    },
    {
      title: '连接类型 P133.0',
      search: false,
      align: 'center',
      dataIndex: 'connectionType',
      valueEnum: {
        0: { text: 'Y' },
        1: { text: '▲' },
      },
      width: 60,
    },
    {
      title: '87Hz运行选择 P133.1',
      search: false,
      align: 'center',
      dataIndex: 'is87Hz',
      valueEnum: {
        0: { text: '50Hz' },
        1: { text: '87Hz' },
      },
      width: 60,
    },
    {
      title: '电机订货号',
      search: false,
      align: 'center',
      dataIndex: 'motorOrderNum',
      width: 80,
    },
    {
      title: '编码器1类型',
      search: false,
      align: 'center',
      dataIndex: 'encoderTypeOne',
      width: 60,
    },
    {
      title: '编码器2选择',
      search: false,
      align: 'center',
      dataIndex: 'isEncoder2Selected',
      valueEnum: {
        0: { text: '编码器2未选择' },
        1: { text: '编码器2已选择' },
      },
      width: 60,
    },
    {
      title: '编码器2类型',
      search: false,
      align: 'center',
      dataIndex: 'encoderTypeTwo',
      width: 60,
    },
    {
      title: '定位编码器 P2502',
      search: false,
      align: 'center',
      dataIndex: 'lrEncoderAssign',
      width: 60,
    },
    {
      title: '电机转数 P2504',
      search: false,
      align: 'center',
      dataIndex: 'gearRationMotor',
      width: 60,
    },
    {
      title: '负载转数 P2505',
      search: false,
      align: 'center',
      dataIndex: 'gearRationLoad',
      width: 60,
    },
    {
      title: '10mm对应的LU (EPOS) P2503',
      search: false,
      align: 'center',
      dataIndex: 'positionAccuracy',
      width: 60,
    },
    {
      title: '每转LU (EPOS) P2506',
      search: false,
      align: 'center',
      dataIndex: 'luLoopEpos',
      width: 60,
    },
    {
      title: '位置设定值滤波器时间常数 (EPOS) P2533 [ms]',
      search: false,
      align: 'center',
      dataIndex: 'posSetpointFiltTimeConst',
      width: 60,
    },
    {
      title: '位置环增益 (EPOS) P2538',
      search: false,
      align: 'center',
      dataIndex: 'kprEpos',
      width: 60,
    },
    {
      title: '位置环积分时间 (EPOS) P2539',
      search: false,
      align: 'center',
      dataIndex: 'lrIntegralTime',
      width: 60,
    },
    {
      title: '速度前馈系数 (EPOS) P2534',
      search: false,
      align: 'center',
      dataIndex: 'coeffVelEpos',
      width: 60,
    },
    {
      title: 'EPOS 最大速度 P2571 [m/min]',
      search: false,
      align: 'center',
      dataIndex: 'vmaxEpos',
      width: 60,
    },
    {
      title: 'EPOS 最大加速度 P2572 [m/s²]',
      search: false,
      align: 'center',
      dataIndex: 'accmaxEpos',
      width: 60,
    },
    {
      title: 'EPOS 最大减速度 P2573 [m/s²]',
      search: false,
      align: 'center',
      dataIndex: 'dccmaxEpos',
      width: 60,
    },
    {
      title: 'EPOS 急动限制 P2574 [m/s³]',
      search: false,
      align: 'center',
      dataIndex: 'jerkEpos',
      width: 60,
    },
    {
      title: 'EPOS 急动限制激活 P2575',
      search: false,
      align: 'center',
      dataIndex: 'jerkActiveEpos',
      width: 60,
    },
    {
      title: 'LR 输出速度极限 P2540',
      search: false,
      align: 'center',
      dataIndex: 'lrOutputVelLimit',
      width: 60,
    },
    {
      title: 'Jog1速度 (EPOS) P2585 [m/min]',
      search: false,
      align: 'center',
      dataIndex: 'jog1VelEpos',
      width: 60,
    },
    {
      title: 'Jog2速度 (EPOS) P2586 [m/min]',
      search: false,
      align: 'center',
      dataIndex: 'jog2VelEpos',
      width: 60,
    },
    {
      title: '静态窗口 P2542',
      search: false,
      align: 'center',
      dataIndex: 'standstillWindow',
      width: 60,
    },
    {
      title: '静态监控时间 P2543 [ms]',
      search: false,
      align: 'center',
      dataIndex: 'standstillMonitoringTime',
      width: 60,
    },
    {
      title: '定位窗口 P2544',
      search: false,
      align: 'center',
      dataIndex: 'posWindow',
      width: 60,
    },
    {
      title: '定位监控时间 P2545 [ms]',
      search: false,
      align: 'center',
      dataIndex: 'posMonitoringTime',
      width: 60,
    },
    {
      title: '动态监控公差 P2546 [LU]',
      search: false,
      align: 'center',
      dataIndex: 'dynMonitoringTol',
      width: 60,
    },
    {
      title: '速度环增益 (Speed) P1460',
      search: false,
      align: 'center',
      dataIndex: 'kpSpeed',
      width: 60,
    },
    {
      title: '速度环积分时间 (Speed) P1462',
      search: false,
      align: 'center',
      dataIndex: 'tnSpeed',
      width: 60,
    },
    {
      title: 'RFG上升时间 (Speed) P1120 [s]',
      search: false,
      align: 'center',
      dataIndex: 'tincSpeed',
      width: 60,
    },
    {
      title: 'RFG下降时间 (Speed) P1121 [s]',
      search: false,
      align: 'center',
      dataIndex: 'tdecSpeed',
      width: 60,
    },
    {
      title: 'RFG开始端平滑时间 P1130 [s]',
      search: false,
      align: 'center',
      dataIndex: 'tstartSpeed',
      width: 60,
    },
    {
      title: 'RFG结束端平滑时间 P1131 [s]',
      search: false,
      align: 'center',
      dataIndex: 'tstopSpeed',
      width: 60,
    },
    {
      title: 'OFF3斜坡下降时间 P1135 [s]',
      search: false,
      align: 'center',
      dataIndex: 'off3TdecSpeed',
      width: 60,
    },
    {
      title: '加速度前馈定标 P1496',
      search: false,
      align: 'center',
      dataIndex: 'accPrectrlScaling',
      width: 60,
    },
  ];

  const g120DeviceColumns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '唯一编号',
      search: false,
      dataIndex: 'identification',
      width: 150,
      render: (text, reocrd, _, action) => (
        <a
          key="deviceInfo"
          onClick={() => {
            setTab('tab1-2');
            setDeviceId(reocrd.id);
            setTab2Disable(false);
            // actionRef.current?.reload();
          }}
        >
          {text}
        </a>
      ),
    },
    {
      title: '设备名称',
      dataIndex: 'deviceName',
      width: 150,
    },
    {
      title: '设备信息登记表编号',
      dataIndex: 'deviceIdentification',
      width: 150,
      search: false,
    },
    {
      title: '轴数量',
      dataIndex: 'driveNum',
      width: 110,
      search: false,
    },
    {
      title: '行业',
      dataIndex: 'vm',
      // align: 'center',
      valueType: 'select',
      width: 80,
      valueEnum: {
        1: { text: '电子' },
        2: { text: '电池' },
        3: { text: '物流' },
        4: { text: '汽车' },
        5: { text: '太阳能' },
        6: { text: '增材制造' },
        7: { text: '包装' },
        8: { text: '食品饮料' },
        9: { text: '金属加工' },
        10: { text: '其他' },
      },
      search: false,
    },
    {
      title: '备注',
      dataIndex: 'memo',
      width: 110,
      search: false,
    },
    {
      title: '创建人',
      search: false,
      dataIndex: 'createName',
      width: 80,
    },
    {
      title: '创建时间',
      search: false,
      dataIndex: 'createDate',
      width: 150,
      sorter: true,
    },
    {
      title: '创建时间', //表头显示的名称
      valueType: 'dateRange',
      hideInTable: true,
      dataIndex: 'createDate',
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      width: 100,
      render: (text, record, _, action) => {
        const buttonList = [];
        buttonList.push(
          <a
            key="editKey"
            onClick={() => {
              setDeviceVisG120(true);
              console.log(record, "----record---");
              setDeviceG120Values(record);
            }}
          >
            编辑
          </a>,
        );
        buttonList.push(
          <a
            key="deleteKey"
            onClick={() => {
              Modal.confirm({
                title: '设备删除',
                content: '是否删除？',
                okText: '是',
                cancelText: '否',
                onOk: async () => {
                  await delG120DeviceInfo({ id: record.id });
                  tableActionRef.current?.reload();
                  message.success('删除成功！');
                },
              });
            }}
          >
            删除
          </a>,
        );
        return buttonList;
      },
    }
  ];

  const treeData: DataNode[] = [
    {
      title: '轴名称',
      key: 'lib0',
    },
    {
      title: '驱动配置',
      key: 'lib4',
      children: [
        {
          title: '负载类型',
          key: 'lib4-0'
        },
        {
          title: '机械结构',
          key: 'lib4-1'
        },
        {
          title: '控制报文 P922',
          key: 'lib4-2'
        },
        {
          title: '附加报文 P8864',
          key: 'lib4-3'
        },
        {
          title: '控制模式',
          key: 'lib4-4'
        },
        {
          title: '电机最大转速 P1082',
          key: 'lib4-5'
        },
      ],
    },
    {
      title: '工艺参数',
      key: 'lib5',
      children: [
        {
          title: 'EPOS',
          key: 'lib5-0',
          children: [
            {
              title: '负载转速 P29248',
              key: 'lib5-0-0',
            },
            {
              title: '电机转速 P29249',
              key: 'lib5-0-1',
            },
            {
              title: '10mm对应的LU',
              key: 'lib5-0-2',
            },
            {
              title: '每转LU P29247',
              key: 'lib5-0-3',
            },
            {
              title: '位置环增益 P29110',
              key: 'lib5-0-4',
            },
            {
              title: '位置环滤波 P2533',
              key: 'lib5-0-5',
            },
            {
              title: '速度前馈系数 P29111',
              key: 'lib5-0-6',
            },
            {
              title: 'EPOS 最大速度 P2571',
              key: 'lib5-0-7',
            },
            {
              title: 'EPOS 最大加速度 P2572',
              key: 'lib5-0-8',
            },
            {
              title: 'EPOS 最大减速度 P2573',
              key: 'lib5-0-9',
            },
            {
              title: 'EPOS 急动限制 P2574',
              key: 'lib5-0-10',
            },
            {
              title: 'EPOS 急动限制激活 P2575',
              key: 'lib5-0-11',
            },

          ],
        },
        {
          title: 'Speed',
          key: 'lib5-1',
          children: [
            {
              title: '速度环增益Kp V90 P29120 /S210 P1460',
              key: 'lib5-1-0',
            },
            {
              title: '速度环积分时间Tn V90 P29121 / S210 P1462',
              key: 'lib5-1-2',
            },
            {
              title: '斜坡上升时间 P1120',
              key: 'lib5-1-3',
            },
            {
              title: '斜坡下降时间 P1121',
              key: 'lib5-1-4',
            },
            {
              title: '斜坡圆弧起始时间 P1130',
              key: 'lib5-1-5',
            },
            {
              title: '斜坡圆弧结束时间 P1131',
              key: 'lib5-1-6',
            },
          ],
        },
      ]
    },

  ];

  const treeDataG120: DataNode[] = [
    {
      title: '设备名称',
      key: 'libG120-0.0',
      children: [
        {
          title: '客户设备名称',
          key: 'libG120-0.0-0',
        },
        {
          title: '非客户设备名称',
          key: 'libG120-0.0-1',
        },
      ]
    },
    {
      title: '轴名称',
      key: 'libG120-0',
    },
    {
      title: '负载类型',
      key: 'libG120-1',
    },
    {
      title: '机械结构',
      key: 'libG120-2',
    },
    {
      title: '驱动配置',
      key: 'libG120-3',
      children: [
        {
          title: '控制报文 P922',
          key: 'libG120-3-0'
        },
        {
          title: '附加报文 P8864',
          key: 'libG120-3-1'
        },
        {
          title: '控制模式 P1300',
          key: 'libG120-3-2'
        },
        {
          title: '转矩限幅值',
          key: 'libG120-3-3',
          children: [
            {
              title: '上限值 P1520 [Nm]',
              key: 'libG120-3-3-0',
            },
            {
              title: '下限值 P1521 [Nm]',
              key: 'libG120-3-3-1',
            },
          ]
        },
        {
          title: '抱闸配置',
          key: 'libG120-3-4',
          children: [
            {
              title: '抱闸配置 P1215',
              key: 'libG120-3-4-0',
            },
            {
              title: '抱闸打开时间 P1216 [ms]',
              key: 'libG120-3-4-1',
            },
            {
              title: '抱闸闭合时间 P1217 [ms]',
              key: 'libG120-3-4-2',
            },
            {
              title: '制动控制诊断分析 P1278',
              key: 'libG120-3-4-3',
            },
            {
              title: '启动频率 P1351 [%]',
              key: 'libG120-3-4-4',
            },
            {
              title: '抱闸控制输出DO',
              key: 'libG120-3-4-5',
            },
          ]
        },
      ]
    },
    {
      title: '电机配置数据',
      key: 'libG120-4',
      children: [
        {
          title: '连接类型 P133.0',
          key: 'libG120-4-0'
        },
        {
          title: '87Hz运行选择 P133.1',
          key: 'libG120-4-1'
        },
        {
          title: '电机订货号',
          key: 'libG120-4-2'
        },
      ]
    },
    {
      title: '编码器配置',
      key: 'libG120-5',
      children: [
        {
          title: '编码器1配置',
          key: 'libG120-5-0',
          children: [
            {
              title: '编码器类型',
              key: 'libG120-5-0-0',
            }
          ],
        },
        {
          title: '编码器2配置',
          key: 'libG120-5-1',
          children: [
            {
              title: '编码器2选择',
              key: 'libG120-5-1-0',
            },
            {
              title: '编码器类型',
              key: 'libG120-5-1-1',
            }
          ],
        },
      ],
    },
    {
      title: '工艺参数',
      key: 'libG120-6',
      children: [
        {
          title: 'EPOS',
          key: 'libG120-6-0',
          children: [
            {
              title: '定位编码器 P2502',
              key: 'libG120-6-0-0'
            },
            {
              title: '电机转数 P2504',
              key: 'libG120-6-0-1'
            },
            {
              title: '负载转数 P2505',
              key: 'libG120-6-0-2'
            },
            {
              title: '10mm对应的LU (EPOS) P2503',
              key: 'libG120-6-0-3'
            },
            {
              title: '每转LU (EPOS) P2506',
              key: 'libG120-6-0-4'
            },
            {
              title: '位置设定值滤波器时间常数 (EPOS) P2533 [ms]',
              key: 'libG120-6-0-5'
            },
            {
              title: '位置环增益 (EPOS) P2538',
              key: 'libG120-6-0-6'
            },
            {
              title: '位置环积分时间 (EPOS) P2539',
              key: 'libG120-6-0-7'
            },
            {
              title: '速度前馈系数 (EPOS) P2534',
              key: 'libG120-6-0-8'
            },
            {
              title: 'EPOS 最大速度 P2571 [m/min]',
              key: 'libG120-6-0-9'
            },
            {
              title: 'EPOS 最大加速度 P2572 [m/s²]',
              key: 'libG120-6-0-10'
            },
            {
              title: 'EPOS 最大减速度 P2573 [m/s²]',
              key: 'libG120-6-0-11'
            },
            {
              title: 'EPOS 急动限制 P2574 [m/s³]',
              key: 'libG120-6-0-12'
            },
            {
              title: 'EPOS 急动限制激活 P2575',
              key: 'libG120-6-0-13'
            },
            {
              title: 'LR 输出速度极限 P2540',
              key: 'libG120-6-0-14'
            },
            {
              title: 'Jog1速度 (EPOS) P2585 [m/min]',
              key: 'libG120-6-0-15'
            },
            {
              title: 'Jog2速度 (EPOS) P2586 [m/min]',
              key: 'libG120-6-0-16'
            },
            {
              title: '静态窗口 P2542',
              key: 'libG120-6-0-17'
            },
            {
              title: '静态监控时间 P2543 [ms]',
              key: 'libG120-6-0-18'
            },
            {
              title: '定位窗口 P2544',
              key: 'libG120-6-0-19'
            },
            {
              title: '定位监控时间 P2545 [ms]',
              key: 'libG120-6-0-20'
            },
            {
              title: '动态监控公差 P2546 [LU]',
              key: 'libG120-6-0-21'
            },
          ],
        },
        {
          title: 'Speed',
          key: 'libG120-6-1',
          children: [
            {
              title: '速度环增益 (Speed) P1460',
              key: 'libG120-6-1-0',
            },
            {
              title: '速度环积分时间 (Speed) P1462',
              key: 'libG120-6-1-1',
            },
            {
              title: 'RFG上升时间 (Speed) P1120 [s]',
              key: 'libG120-6-1-2',
            },
            {
              title: 'RFG下降时间 (Speed) P1121 [s]',
              key: 'libG120-6-1-3',
            },
            {
              title: 'RFG开始端平滑时间 P1130 [s]',
              key: 'libG120-6-1-4',
            },
            {
              title: 'RFG结束端平滑时间 P1131 [s]',
              key: 'libG120-6-1-5',
            },
            {
              title: 'OFF3斜坡下降时间 P1135 [s]',
              key: 'libG120-6-1-6',
            },
            {
              title: '加速度前馈定标 P1496',
              key: 'libG120-6-1-7',
            },
          ],
        },
      ],
    },
  ];
  
  const onExpand = (expandedKeysValue: React.Key[]) => {
    console.log('onExpand', expandedKeysValue);
    // if not set autoExpandParent to false, if children expanded, parent can not collapse.
    // or, you can remove all expanded children keys.
    setExpandedKeys(expandedKeysValue);
    setAutoExpandParent(false);
  };

  const onCheck = (checkedKeysValue: React.Key[]) => {
    console.log('onCheck', checkedKeysValue);
    setCheckedKeys(checkedKeysValue);
  };

  const onFinish = async (values: Record<string, any>) => {
    try {
      const result = driveRef.current.getFieldsValue();
      console.log(result, '---result2---');
      if (axiosCreate) {
        result.id = (Math.random() * 1000000).toFixed(0);
        setDataSource([...dataSource, result]);
        await addDriveParaLibEngineer(result);
        message.success('添加成功');
      } else {
        if (result.id !== null && result.id !== undefined) {
          for (let i = 0; i < dataSource.length; i++) {
            if (dataSource[i].id === result.id) {
              Object.assign(dataSource[i], result);
            }
          }
          setDataSource(dataSource);
          await updateDriveParaLibEngineer(result);
          message.success('更新成功');
        }
      }
      actionRef.current.reload();
      setLibCommVis(false);
    } catch{}
  };

  const onG120Finish = async () => {
    try {
      const result = driveRef.current.getFieldsValue();
      // delete result.motorManufacturer;
      // delete result.voltageType;
      // delete result.encoderManufacturerOne;
      // delete result.encoderTypeOne;
      // delete result.encoderManufacturerTwo;
      // delete result.encoderTypeTwo;
      console.log(result, "---result---");
      if (g120Create) {
        result.id = (Math.random() * 1000000).toFixed(0);
        setG120DataSource([...g120DataSource, result]);
        await addDriveParaLibG120Eng({
          ...result,
          deviceInfoExtraId: deviceId,
        });
        message.success('添加成功');
      } else {
        if (result.id !== null && result.id !== undefined) {
          for (let i = 0; i < g120DataSource.length; i++) {
            if (g120DataSource[i].id === result.id) {
              Object.assign(g120DataSource[i], result);
            }
          }
          setG120DataSource(g120DataSource);
          await updateDriveParaLibG120Eng({
            ...result,
            deviceInfoExtraId: deviceId,
          });
          message.success('更新成功');
        }
      }
      actionRef.current?.reload();
      setG120CommVis(false);
    } catch { };
  };


  return (
    <PageHeaderWrapper title={false} breadcrumb={undefined}>
      <ProCard split="vertical">
        <ProCard split="horizontal" colSpan="20%">
          <ProCard title="驱动选择" colSpan="100%" style={{ maxWidth: '100%', height: '10%' }}>
            <Radio.Group onChange={onRadioChange} value={radioValue} style={{textAlign: "center"}}>
              <Radio value={1}>V90/S210</Radio>
              <Radio value={2}>G120</Radio>
            </Radio.Group>
          </ProCard>
          <ProCard title="可选显示项" colSpan="100%" style={{ maxWidth: '100%', height: '90%' }}>
            <Tree
              checkable
              onExpand={(expandedKeysValue: React.Key[]) => {
                console.log('onExpand', expandedKeysValue);
                // if not set autoExpandParent to false, if children expanded, parent can not collapse.
                // or, you can remove all expanded children keys.
                setExpandedKeys(expandedKeysValue);
                setAutoExpandParent(false);
              }}
              expandedKeys={expandedKeys}
              autoExpandParent={autoExpandParent}
              onCheck={onCheck}
              checkedKeys={checkedKeys}
              treeData={radioValue == 1? treeData : tab == "tab1-2" || tab == "tab1-3" ? treeDataG120 : []}
              
            />
          </ProCard>
        </ProCard>
        {radioValue == 1 ? 
          <ProCard colSpan="80%" style={{ maxWidth: '100%', height: '100%' }}>
            <ProList<any>
              headerTitle="V90/S210驱动参数列表"
              search={{}}
              actionRef={actionRef}
              rowKey="id"
              rowSelection={rowSelection}
              expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
              dataSource={dataSource}
              toolBarRender={() => [
                <Button
                  key="button"
                  icon={<PlusOutlined />}
                  type="primary"
                  onClick={() => {
                    setUploadVis(true);
                  }}
                >
                  导入
                </Button>,
                <Button
                  key="button"
                  icon={<PlusOutlined />}
                  type="primary"
                  onClick={() => {
                    setValues({});
                    setLibCommVis(true);
                    setAxiosCreate(true);
                  }}
                >
                  新建
                </Button>
              ]}
              metas={{
                title: {
                  dataIndex: 'index',
                  valueType: 'index',
                  search: false,
                },

                subTitle: {
                  search: false,
                  render: (text, row) => {
                    return (
                      <DriveParaSubtitle row={row} checkedKeys={checkedKeys} isEngineer={true}/>
                    );
                  }
                },

                description: {
                  dataIndex: 'para',
                  search: false,
                  render: (_, row) => {
                    return (
                      <DriveParaDescription isEngineer={true} row={row}/>
                      );
                  }
                },

                content: {
                  search: false,
                },
                actions:{
                  search: false,
                  render: (text, row) => [
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="modify"
                      onClick={async () => {
                        setAxiosCreate(false);
                        setLibCommVis(true);
                        if (row.vmaxEpos == null && row.vmaxEpos == undefined) {
                          setValues({...row});
                        } else if (row.positionAccuracy == null && row.positionAccuracy == undefined) {
                          setValues({...row});
                        } else {
                          setValues({ ...row, vmaxEposTran: 6 * row.vmaxEpos * row.positionAccuracy });
                        }
                      }}
                    >
                      编辑
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="copy"
                      onClick={async () => {
                        let addone = {};
                        dataSource
                          .filter((item) => item.id == row.id)
                          .map((item) => {
                            addone = { ...item };
                          });
                        addone.id = (Math.random() * 1000000).toFixed(0);  
                        setDataSource([...dataSource, addone]);
                        await addDriveParaLibEngineer(addone);
                        actionRef.current.reload();
                      }}
                    >
                      复制
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="delete"
                      onClick={async () => {
                        setDataSource(dataSource.filter((item) => item.id !== row.id));
                        await delDriveParaLibEngineer(row);
                        actionRef.current.reload();
                      }}
                    >
                      删除
                    </a>,
                  ],
                },

                motorOrderNum: {
                  title: '电机订货号'
                },
                
              }}
              request={async (params = {}, sort, filter) => {
                console.log(params, sort, filter);
                const result = await getDriveParaLibEngineerByPage(params);
                console.log(result, "---result---");
                setDataSource(result.data.content);
                return {
                  data: result.data.content,
                  total: result.data.totalElements,
                  success: result.success,
                };
              }}
              pagination={{
                showSizeChanger: true,
              }}
              />
            <DriveParaLibCommon
              visible={libCommVis}
              defaultParaVisible={false}
              title="工程师驱动参数库新建"
              disable={false}
              values={values}
              ref={driveRef}
              initialValues={values}
              onCancel={() => {
                setLibCommVis(false);
              }}
              onOk={onFinish}
            />
            <UploadFileSave
              visible={uploadVis}
              tableHeader={columns}
              errorStatus={false}
              ref={uploadRef}
              onOk={async (tables, tableHeader) => {
                console.log(tables, "---tables---");
                
                console.log(uploadRef.current.fileList, '文件测试---');
                // formData.append('file', uploadRef.current.fileList);
                // console.log(formData, "---formData---");
                // uploadRef.current.fileList.map((file) => {
                //   formData.append('file', file);
                // });
                await uploadDriveParaLibEngineerExcel(formData);
                console.log(formData, "---formData---");
                // setDataSource([...dataSource, tables]);
                actionRef.current.reload();
                setUploadVis(false);
              }}
              onChange={(file) => {
                formData.append('file', file);
                console.log(file, "---file---");
              }}
              onCheck={() => {}}
              onCancel={() => {
                setUploadVis(false);
              }}
              title="驱动参数库上传预览"
            />
          </ProCard> :
          <ProCard
            colSpan="80%"
            style={{ maxWidth: '100%', height: '100%' }}
            layout='center'
            tabs={{
              type: 'card',
              tabPosition,
              activeKey: tab,
              destroyInactiveTabPane: true,
              items: [
                {
                  label: '设备管理',
                  key: 'tab1-1',
                  children: [
                    <ProTable
                      headerTitle="设备列表"
                      actionRef={tableActionRef}
                      formRef={tableRef}
                      rowKey="id"
                      columns={g120DeviceColumns}
                      // columns={G120DriveParaColumns("a")}
                      toolBarRender={(action, { selectedRows, selectedRowKeys }) => { 
                        return [
                          <Button
                            key="button"
                            icon={<PlusOutlined />}
                            type="primary"
                            onClick={async () => {
                              await addG120DeviceInfo({
                                // id: (Math.random() * 1000000).toFixed(0),
                                deviceName: 'Temp_Device_1',
                                driveNum: 0,
                                engineerDeviceG120: 1,
                              });
                              message.success("新建设备成功");
                              tableActionRef.current?.reload();
                            }}
                          >
                            新建设备
                          </Button>
                        ];
                      }}
                      revalidateOnFocus={false}
                      request={async (params = {}, sort, filter) => { 
                        let result;
                        result = await getDeviceInfoLibByPage({
                          ...params,
                          engineerDeviceG120: 1,
                        });
                        return {
                          data: result.data.content,
                          total: result.data.totalElements,
                          success: result.success,
                        };    
                      }}
                      onDataSourceChange={(value) => {
                        // 如果实在要保存新的值就需要在这边进行处理
                        // console.log(value, selectedRowKeys, '---teee');
                      }}
                      rowSelection={rowSelection}
                      pagination={{
                        showSizeChanger: true,
                      }}
                      scroll={{ x: 1070, y: 350 }}
                    />,
                    <ModalForm
                      title="选择设备"
                      visible={deviceVisG120}
                      initialValues={deviceG120Values}
                      formRef={formRef}
                      onFinish={async (temp) => {
                        console.log(temp, '---temp---');
                        console.log(deviceG120Values.id, "---deviceG120Values.id---");
                        await updateG120DeviceInfo({
                          ...temp,
                          id: deviceG120Values.id,
                          identification: deviceG120Values.identification,
                          driveNum: deviceG120Values.driveNum,
                          engineerDeviceG120: 1,
                        });
                        setDeviceVisG120(false);
                        tableActionRef.current?.reload();
                      }}
                      // onValuesChange={ }
                      modalProps={{
                        destroyOnClose: true,
                        onCancel: () => { setDeviceVisG120(false) },
                      }}
                      layout='horizontal'
                      grid={grid}
                      rowProps={{
                        gutter: [12, 0],
                      }}
                    >
                      <ProFormGroup key="common1-2">
                        <ProFormText
                          width="md"
                          name="deviceName"
                          label="设备名称"
                          colProps={{ md: 14, xl: 10 }}
                          rules={[{ required: true, message: '请输入设备名称信息' }]}
                        />
                        <ProFormSelect
                          fieldProps={{
                            //这里使用了select的onChange方法，必须使用这样的写法来进行调用onChange方法
                            onChange: (val, val2) => {
                              console.log(val, val2);
                            },
                          }}
                          colProps={{ md: 12, xl: 6 }}
                          // initialValue={1}
                          name="vm"
                          label="行业"
                          options={[
                            { label: '电子', value: 1 },
                            { label: '电池', value: 2 },
                            { label: '物流', value: 3 },
                            { label: '汽车', value: 4 },
                            { label: '太阳能', value: 5 },
                            { label: '增材制造', value: 6 },
                            { label: '包装', value: 7 },
                            { label: '食品饮料', value: 8 },
                            { label: '金属加工', value: 9 },
                            { label: '其他', value: 10 },
                          ]}
                        />
                        <ProFormTextArea
                          colProps={{ span: 22 }}
                          name="memo"
                          label="备注"
                        />
                      </ProFormGroup>
                      <ProFormGroup key="common1-1" style={{ marginTop: '10px' }}>
                        <ProFormSelect
                          width="md"
                          name="isFromCusDevice"
                          label="是否来自客户设备信息"
                          options={[
                            { label: '是', value: 1 },
                            { label: '否', value: 0 },
                          ]}
                          colProps={{ md: 14, xl: 10 }}
                          rules={[{ required: true, message: '此项是必填项目' }]}
                        />
                      
        
                        <ProFormDependency name={['isFromCusDevice']}>
                          {({ isFromCusDevice }) => {
                            if (isFromCusDevice === 1) {
                              return [
                                <ProFormSelect
                                  showSearch
                                  width="md"
                                  name="cusDeviceId"
                                  label="设备信息"
                                  // rules={[{ required: true, message: '必须选取设备' }]}
                                  colProps={{ md: 12, xl: 12 }}
                                  debounceTime={1000}
                                  request={async (params) => {
                                    console.log(params, '--params-');
                                    const result = await calcDeviceList({ blurry: params.keyWords });
                                    return result.data.map((item) => {
                                      return {
                                        key: item.id,
                                        label: item.identification,
                                        value: item.id,
                                      };
                                    });
                                  }}
                                  fieldProps={{
                                    onChange: () => {
                                      formRef.current?.setFieldsValue({
                                        isFromCusDevice: 1,
                                      });
                                      }
                                  }}
                                />
                              ];
                            } else {}
                          }}
                        </ProFormDependency>
                      </ProFormGroup>
                    </ModalForm>,
                  ]
                },
                {
                  label: '轴信息管理',
                  key: 'tab1-2',
                  disabled: tab2Disable,
                  children: [
                    <ProList<any>
                      headerTitle="G120驱动参数列表"
                      search={{}}
                      actionRef={actionRef}
                      rowKey="id"
                      rowSelection={rowSelection}
                      expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
                      // dataSource={}
                      toolBarRender={() => [
                        // <Button
                        //   key="button"
                        //   icon={<PlusOutlined />}
                        //   type="primary"
                        //   onClick={() => {
                        //     setG120CommVis(true);
                        //     setG120Create(true);
                        //     setG120Values({});
                        //   }}
                        // >
                        //   新建设备
                        // </Button>,
                        <Button
                          key="button"
                          icon={<PlusOutlined />}
                          type="primary"
                          onClick={() => {
                            setG120CommVis(true);
                            setG120Create(true);
                            setG120Values({});
                          }}
                        >
                          新建轴
                        </Button>,
                        <Button
                          key="button"
                          icon={<PlusOutlined />}
                          type="primary"
                          onClick={() => {
                            setUploadVisG120(true);
                          }}
                        >
                          导入
                        </Button>,
                        // <Button
                        //   key="button"
                        //   icon={<PlusOutlined />}
                        //   type="primary"
                        //   onClick={() => {
                        //     setDeviceVisG120(true);
                        //   }}
                        // >
                        //   选择设备
                        // </Button>,
                        <Button
                          key="button"
                          icon={<DeleteOutlined />}
                          type="primary"
                          onClick={() => {
                            Modal.confirm({
                              title: '批量删除',
                              content: '是否删除？',
                              okText: '是',
                              cancelText: '否',
                              onOk: async () => {
                                await delDriveParasLibG120Eng(selectedRowKeys);
                                actionRef.current?.reload();
                                message.success('删除成功！');
                              },
                            });
                          }}
                        >
                          批量删除
                        </Button>,
                      ]}
                      metas={{
                        title: {
                          dataIndex: 'index',
                          valueType: 'index',
                          search: false,
                        },
        
                        subTitle: {
                          search: false,
                          render: (text, row) => {
                            return (
                              <G120DriveParaSubtitle
                                row={row}
                                checkedKeys={checkedKeys}
                                // extDeviceLink={() => {
                                //   setDeviceG120Values({
                                //     isFromCusDevice: 0,
                                //     deviceName: row.extraDeviceName,
                                //     vm: row.extraDeviceVm,
                                //     memo: row.extraDeviceMemo,
                                //   });
                                //   setDeviceVisG120(true);
                                // }}
                                // cusDeviceLink={() => {
                                //   console.log(row, "---row.history---");
                                //   if (row.cusDeviceId !== null) {
                                //     history.push({
                                //       pathname: `/device/deviceInfoDetail`,
                                //       query: {
                                //         id: row.cusDeviceId,
                                //       },
                                //     });
                                //   }
                                // }}
                              />
                            );
                          }
                        },
        
                        description: {
                          dataIndex: 'para',
                          search: false,
                          render: (_, row) => {
                            return (
                              <>
                                {/* <Tag>{'电机订货号' + row.g120Motor.motorOrderNum}</Tag> */}
                              </>
                            );
                          }
                        },
        
                        content: {
                          search: false,
                        },
                        actions:{
                          search: false,
                          render: (text, row) => [
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="modify"
                              onClick={async () => {
                                setG120Create(false);
                                setG120CommVis(true);
                                console.log(row, '---initialValues---');
                                setG120Values({ ...row });
                              }}
                            >
                              编辑
                            </a>,
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="copy"
                              onClick={async () => {
                                let addone = {};
                                console.log(g120DataSource, "---g120DataSource---");
                                g120DataSource
                                  .filter((item) => item.id == row.id)
                                  .map((item) => {
                                    addone = { ...item };
                                  });
                                addone.id = (Math.random() * 1000000).toFixed(0);  
                                setG120DataSource([...g120DataSource, addone]);
                                await addDriveParaLibG120Eng({
                                  ...addone,
                                  deviceInfoExtraId: deviceId,
                                });
                                actionRef.current.reload();
                              }}
                            >
                              复制
                            </a>,
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="delete"
                              onClick={async () => {
                                setG120DataSource(g120DataSource.filter((item) => item.id !== row.id));
                                await delDriveParaLibG120Eng({
                                  ...row,
                                });
                                actionRef.current.reload();
                              }}
                            >
                              删除
                            </a>,
                          ],
                        },
        
                        shaftName: {
                          title: '轴名称',
                        },
                      }}
                      request={async (params = {}, sort, filter) => {
                        console.log(params, sort, filter);
                        console.log(deviceId, "---deviceId---");
                        const result = await getDriveParaLibG120EngByPage({
                          ...params,
                          // deviceInfoId: null,
                          deviceInfoExtraId: deviceId,
                        });
                        // setDeviceId(null);
                        console.log(result, "---result---");
                        setG120DataSource(result.data.content);
                        return {
                          data: result.data.content,
                          total: result.data.totalElements,
                          success: result.success,
                        };
                      }}
                      pagination={{
                        showSizeChanger: true,
                      }}
                    />,
        
                    // <G120LibEngCommon
                    //   visible={false}
                    //   title="G120工程师驱动参数库新建"
                    //   onOk={() => { actionRef.current.reload() }}
                    //   onCancel={() => { setG120CommVis(false) }}
                    //   initialValues={g120Values}
                    //   // isCreate={g120Create}
                    // />,
        
                    <G120LibEngShaftCommon
                      visible={g120CommVis}
                      title='G120工程师驱动参数库新建'
                      disabled={false}
                      values={g120Values}
                      initialValues={g120Values}
                      ref={driveRef}
                      onOk={ onG120Finish }
                      onCancel={() => {
                        setG120CommVis(false);
                      }}
                      isG120Eng={true}
                    />,
        
                    <UploadFileSave
                      visible={uploadVisG120}
                      tableHeader={g120Columns}
                      errorStatus={false}
                      ref={uploadRef}
                      onOk={async (tables, tableHeader) => {
                        console.log(tables, "---tables---");
                        
                        console.log(uploadRef.current.fileList, '文件测试---');
                        // formData.append('file', uploadRef.current.fileList);
                        // console.log(formData, "---formData---");
                        // uploadRef.current.fileList.map((file) => {
                        //   formData.append('file', file);
                        // });
                        if (deviceId !== null) {
                          formData.append('deviceInfoExtraId', deviceId);
                        }
                        await uploadDriveParasLibG120EngExcel(formData);
                        console.log(formData, "---formData---");
                        // setDataSource([...dataSource, tables]);
                        actionRef.current.reload();
                        setUploadVisG120(false);
                      }}
                      onChange={(file) => {
                        formData.append('file', file);
                        console.log(file, "---file---");
                      }}
                      onCheck={() => {}}
                      onCancel={() => {
                        setUploadVisG120(false);
                      }}
                      title="G120工程师驱动参数库上传预览"
                    />,
                  ],
                },
                {
                  label: '轴信息总览',
                  key: 'tab1-3',
                  children: [
                    <ProList<any>
                      headerTitle="G120驱动参数列表"
                      search={{}}
                      actionRef={actionRef}
                      rowKey="id"
                      rowSelection={rowSelection}
                      expandable={{ expandedRowKeys, onExpandedRowsChange: setExpandedRowKeys }}
                      metas={{
                        title: {
                          dataIndex: 'index',
                          valueType: 'index',
                          search: false,
                        },
        
                        subTitle: {
                          search: false,
                          render: (text, row) => {
                            return (
                              <G120DriveParaSubtitle
                                row={row}
                                checkedKeys={checkedKeys}
                              />
                            );
                          }
                        },
        
                        description: {
                          dataIndex: 'para',
                          search: false,
                          render: (_, row) => {
                            return (
                              <>
                                {/* <Tag>{'电机订货号' + row.g120Motor.motorOrderNum}</Tag> */}
                              </>
                            );
                          }
                        },
        
                        content: {
                          search: false,
                        },
                        actions:{
                          search: false,
                          render: (text, row) => [
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="modify"
                              onClick={async () => {
                                setG120Create(false);
                                setG120CommVis(true);
                                console.log(row, '---initialValues---');
                                setG120Values({ ...row });
                              }}
                            >
                              编辑
                            </a>,
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="copy"
                              onClick={async () => {
                                let addone = {};
                                console.log(g120DataSource, "---g120DataSource---");
                                g120DataSource
                                  .filter((item) => item.id == row.id)
                                  .map((item) => {
                                    addone = { ...item };
                                  });
                                addone.id = (Math.random() * 1000000).toFixed(0);  
                                setG120DataSource([...g120DataSource, addone]);
                                await addDriveParaLibG120Eng({
                                  ...addone,
                                  deviceInfoExtraId: deviceId,
                                });
                                actionRef.current.reload();
                              }}
                            >
                              复制
                            </a>,
                            <a
                              href={row.html_url}
                              target="_blank"
                              rel="noopener noreferrer"
                              key="delete"
                              onClick={async () => {
                                setG120DataSource(g120DataSource.filter((item) => item.id !== row.id));
                                await delDriveParaLibG120Eng(row);
                                actionRef.current.reload();
                              }}
                            >
                              删除
                            </a>,
                          ],
                        },

                        deviceExtraName: {
                          title: '设备名称',
                        },
                        shaftName: {
                          title: '轴名称',
                        },
                        createDate: {
                          title: '创建时间',
                          valueType: 'dateRange',
                        },
                        // deviceIdentification: {
                        //   title: '客户设备编号',
                        // },
                        // deviceExtraName: {
                        //   title: '非客户设备名称',
                        // },
        
                      }}
                      request={async (params = {}, sort, filter) => {
                        console.log(params, sort, filter);
                        console.log(deviceId, "---deviceId---");
                        const result = await getDriveParaLibG120EngByPage({
                          ...params,
                        });
                        // setDeviceId(null);
                        console.log(result, "---result---");
                        setG120DataSource(result.data.content);
                        return {
                          data: result.data.content,
                          total: result.data.totalElements,
                          success: result.success,
                        };
                      }}
                      pagination={{
                        showSizeChanger: true,
                      }}
                    />,
                  ],
                },
              ],
              onChange: (key) => {
                // actionRef.current?.reload();
                setTab(key);
                setTab2Disable(true);
              }
            }}
          >
              
          </ProCard>
        }
      </ProCard>
    </PageHeaderWrapper>
  );
};

export default DriveParaLib;